<?php
/**
*所有的销售数据
*/
require("../include/init.php");
$mysql=mysql::getIns();

date_default_timezone_set('Asia/Shanghai');
$maxtime=time();
$mintime=$maxtime-10*60;



//统计当天累计人数数
$t = time();
$start = mktime(0,0,0,date("m",$t),date("d",$t),date("Y",$t));
$end = mktime(23,59,59,date("m",$t),date("d",$t),date("Y",$t));
$sql="select count(*) from alldev where whitelist <> '1' and timestamp > $start and timestamp < $end and shop <> 'Audi City BeiJing'";
$allday=$mysql->getOne($sql);
// echo $allday;
// exit;



/*************************************

	进店频次(每天统计一次,今天累计人数的进店频次)


************************************/
//今天累计进店人数为$allday;

//统计进店频次为2次的
$sql="select count(*) from alldev where whitelist <> '1' and timestamp > $start and timestamp < $end  and visittimes='2' and shop <> 'Audi City BeiJing'";
$visittwo=$mysql->getOne($sql);
// echo $visittwo;
// exit;

//统计进店频次为3次
$sql="select count(*) from alldev where whitelist <> '1' and timestamp > $start and timestamp < $end  and visittimes='3' and shop <> 'Audi City BeiJing'";
$visitthree=$mysql->getOne($sql);
// echo $visitthree;
// exit;



//统计进店频次为3次以上
$sql="select count(*) from alldev where whitelist <> '1' and timestamp > $start and timestamp < $end  and visittimes > '3' and shop <> 'Audi City BeiJing'";
$visitmore=$mysql->getOne($sql);
// echo $visitmore;
// exit;

//计算频次

//两次
$vtwo=floor(($visittwo/$allday)*100);
// echo $vtwo;
// exit;
//三次
$vthree=floor(($visitthree/$allday)*100);
// echo $vthree;
// exit;

//三次以上
$vmore=floor(($visitmore/$allday)*100);
// echo $vmore;
// exit;

//一次
$vone=100-$vtwo-$vthree-$vmore;
// echo $vone;
// exit;


$redis = new Redis();
  //连接服务器
  $redis->connect("localhost");
  //授权
  $redis->auth("redis=pwd@2016");
$redis->hmset('National_SaleDirector',
array(
  'allday'=>$allday,
  'vtwo'=>$vtwo,
  'vthree'=>$vthree,
  'vmore'=>$vmore,
  'vone'=>$vone,
));
